/* -----------------------------------------------------------------------
 * Random testing of Gardens Card
 *
 * -----------------------------------------------------------------------
 */

#include "dominion.h"
#include "dominion_helpers.h"
#include <string.h>
#include <stdio.h>
#include <assert.h>
#include "rngs.h"
#include <stdlib.h>
#include <time.h>
#include <math.h>

// set NOISY_TEST to 0 to remove printfs from output
#define NOISY_TEST 1

void randomGardens() {
    //Game setup
    int i, j;
    int seed = 1000;
    int numPlayer = 2;
    int card = gardens;
    int k[10] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall};
    int allCards[17] = {adventurer, council_room, feast, gardens, mine
               , remodel, smithy, village, baron, great_hall, copper, silver, gold, curse, estate, duchy, province};
    struct gameState G;
    int testHandCount;
    int testDeckCount;
    int testDiscardCount;
    int testPoints;
    int p = 0;

    int randomTests = 5000;

    printf ("Random testing playing 'gardens':\n");

    for (i = 0; i < randomTests; i++) {
        initializeGame(numPlayer, k, seed, &G);
        //Need to randomize size and content of deck, content and size of player's hands
        if (i % 100 == 0)
            testHandCount = (rand() % 10) + 1; //Random size of hand using max hand size
        else
            testHandCount = (rand() % 10) + 1; //Random size of hand between 1 and 10, much more realistic
        testDeckCount = (rand() % 50); //Random size of deck between 0 - max deck size
        testDiscardCount = (rand() % 20); 
        G.handCount[p] = testHandCount;
        G.deckCount[p] = testDeckCount;
        G.discardCount[p] = testDiscardCount;

        //Set random cards in hand and deck
        for (j = 0; j < testHandCount; j++) {
            int randCardNum = (rand() % 17);
            if (randCardNum == 3)
                randCardNum = 2; //Make sure no gardens are included in hand, deck, or discard
            G.hand[p][j] = allCards[randCardNum];
        }
        for (j = 0; j < testDeckCount; j++) {
            int randCardNum = (rand() % 17);
            if (randCardNum == 3)
                randCardNum = 2;
            G.deck[p][j] = allCards[randCardNum];
        }
        for (j = 0; j < testDiscardCount; j++) {
            int randCardNum = (rand() % 17);
            if (randCardNum == 3)
                randCardNum = 2;
            G.discard[p][j] = allCards[randCardNum];
        }

        testPoints = scoreFor(p, &G);

#if (NOISY_TEST == 1)    
        printf("Before having gardens in their possession, player has %d victory points and %d total cards.\n", scoreFor(p, &G), (testHandCount + testDeckCount + testDiscardCount));
#endif

        //Put the adventurer card in the hand
        G.hand[p][0] = card;

        testPoints = testPoints + floor((testHandCount + testDeckCount + testDiscardCount) / 10);

#if (NOISY_TEST == 1)    
        printf("After having gardens in their possession, player has %d victory points. %d expected.\n", scoreFor(p, &G), testPoints);

#endif
        assert(scoreFor(p, &G) == testPoints);
    }

    printf("All tests passed!\n");
}



int main() {
    srand(time(NULL));
    randomGardens();
    return 0;
}
